import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { ossPut } from '../utils/oss';

@Injectable()
export class UploadService {
  async uploadFile(file: Express.Multer.File): Promise<{ objectName: string }> {
    // 调用OSS上传文件的函数
    const ossResult = await ossPut(file.filename);

    if (!ossResult) {
      throw new HttpException('上传文件失败', HttpStatus.INTERNAL_SERVER_ERROR);
    }
    
    return {
      objectName: ossResult.name
    };
  }
}
